package com.sun.personal.juc;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author syh
 * @date 2021/7/6 13:47
 */
public class CyclicBarrierDemo {

    public static void main(String[] args)  {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(7,()->{
            System.out.println("现在人到齐了，开会");
        });

        for (int i = 0; i < 7; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName() + "\t号员工进来开会了");
                try {
                    cyclicBarrier.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            },String.valueOf(i)).start();

        }
    }
}

